@import '../common/style/base.less';

@checkbox: ~'@{prefix}-checkbox';

@checkbox-border-width: 4rpx;
@checkbox-icon-size: var(--td-checkbox-icon-size, 48rpx);
@checkbox-font-size: var(--td-checkbox-font-size, 32rpx);
@checkbox-title-line-height: var(--td-checkbox-title-line-height, 48rpx);
@checkbox-description-line-height: var(--td-checkbox-description-line-height, 44rpx);
@checkbox-vertical-padding: var(--td-checkbox-vertical-padding, 32rpx);
@checkbox-bg-color: var(--td-checkbox-bg-color, @bg-color-container);
@checkbox-border-color: var(--td-checkbox-border-color, @component-stroke);
@checkbox-title-color: var(--td-checkbox-title-color, @text-color-primary);
@checkbox-title-disabled-color: var(--td-checkbox-title-disabled-color, @text-color-disabled);
@checkbox-description-color: var(--td-checkbox-description-color, @text-color-secondary);
@checkbox-description-disabled-color: var(--td-checkbox-description-disabled-color, @text-color-disabled);
@checkbox-icon-color: var(--td-checkbox-icon-color, @component-border);
@checkbox-icon-disabled-color: var(--td-checkbox-icon-disabled-color, @brand-color-disabled);
@checkbox-icon-disabled-bg-color: var(--td-checkbox-icon-disabled-bg-color, @bg-color-component-disabled);
@checkbox-icon-checked-color: var(--td-checkbox-icon-checked-color, @brand-color);
@checkbox-tag-active-bg-color: var(--td-checkbox-tag-active-bg-color, @brand-color-light);
@checkbox-tag-active-color: var(--td-checkbox-tag-active-color, @brand-color);

.@{checkbox} {
  display: inline-flex;
  vertical-align: middle;
  position: relative;
  font-size: @checkbox-font-size;
  background: @checkbox-bg-color;

  &:focus {
    outline: 0;
  }

  &--block {
    display: flex;
    padding: @checkbox-vertical-padding;
  }

  &--right {
    flex-direction: row-reverse;
  }

  .limit-title-row {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .image-center {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }

  &__icon-left {
    margin-right: 20rpx;
    width: 40rpx;
  }

  &__icon-right {
    right: 0px;
    display: contents;
    .image-center();
  }

  &__icon-image {
    width: @checkbox-icon-size;
    height: @checkbox-icon-size;
    vertical-align: top;
  }

  &__icon {
    position: relative;
    display: block;
    width: @checkbox-icon-size;
    height: @checkbox-icon-size;
    color: @checkbox-icon-color;
    font-size: @checkbox-icon-size;
    margin-top: calc((@checkbox-title-line-height - @checkbox-icon-size) / 2);

    &:empty {
      display: none;
    }

    &--checked {
      color: @checkbox-icon-checked-color;
    }

    &--disabled {
      cursor: not-allowed;
      color: @checkbox-icon-disabled-color;
    }

    &--left {
      margin-right: 16rpx;
    }

    &-circle {
      width: calc((@checkbox-icon-size - @checkbox-border-width) * 2);
      height: calc((@checkbox-icon-size - @checkbox-border-width) * 2);
      border: calc(@checkbox-border-width * 2) solid @checkbox-icon-color;
      border-radius: 50%;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) scale(0.5);
      box-sizing: border-box;

      &--disabled {
        background: @checkbox-icon-disabled-bg-color;
      }
    }

    &-rectangle {
      width: calc((@checkbox-icon-size - @checkbox-border-width * 2) * 2);
      height: calc((@checkbox-icon-size - @checkbox-border-width * 2) * 2);
      border: calc(@checkbox-border-width * 2) solid @checkbox-icon-color;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) scale(0.5);
      box-sizing: border-box;

      &--disabled {
        background: @checkbox-icon-disabled-bg-color;
      }
    }

    &-line {
      &::before,
      &::after {
        content: '';
        display: block;
        position: absolute;
        width: 5rpx;
        border-radius: 2rpx;
        background: @checkbox-icon-checked-color;
        transform-origin: top center;
      }

      &::before {
        height: 16rpx;
        left: 8rpx;
        top: 22rpx;
        transform: rotate(-45deg);
      }

      &::after {
        height: 26rpx;
        right: 8rpx;
        top: 14rpx;
        transform: rotate(45deg);
      }

      &--disabled {
        &::before,
        &::after {
          background: @checkbox-icon-disabled-color;
        }
      }
    }
  }

  &__content {
    flex: 1;
  }

  &__title {
    color: @checkbox-title-color;
    line-height: @checkbox-title-line-height;
    .limit-title-row();

    &--disabled {
      color: @checkbox-title-disabled-color;
    }
  }

  &__description {
    color: @checkbox-description-color;
    .limit-title-row();
    font-size: 28rpx;
    line-height: @checkbox-description-line-height;

    &--disabled {
      color: @checkbox-description-disabled-color;
    }
  }

  &__title + &__description:not(:empty) {
    margin-top: 8rpx;
  }

  &__border {
    position: absolute;
    bottom: 0;
    left: 96rpx;
    right: 0;
    height: 1px;
    background: @checkbox-border-color;
    transform: scaleY(0.5);

    &--right {
      left: 32rpx;
    }
  }

  &--tag {
    font-size: 28rpx;
    padding-top: 16rpx;
    padding-bottom: 16rpx;
    text-align: center;
    background-color: @bg-color-secondarycontainer;
    border-radius: 12rpx;

    &.@{checkbox}--checked {
      color: @checkbox-tag-active-color;
      background-color: @checkbox-tag-active-bg-color;
    }

    .@{checkbox}__title--checked {
      color: @checkbox-tag-active-color;
    }

    .@{checkbox}__content {
      margin-right: 0;
    }
  }
}
